package com.xxwy.dependency.ioccontainer;

import com.xxwy.dependency.User;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

import java.util.Map;

/**
 * ioc 容器实例
 * @author wy
 * @date 2020/4/20 14:47
 */
public class BeanFactoryDemo {

  public static void main(String[] args) {
    //创建BeanFactory容器
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

    //加载配置
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    int i = reader.loadBeanDefinitions(new ClassPathResource("/META-INF/dependency-lookup-context.xml"));
    System.out.println("bean定义的数量" + i);

    Map<String, User> beansOfType = beanFactory.getBeansOfType(User.class);
    beansOfType.entrySet().forEach(System.out::println);


  }
}
